<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>东财新股</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">				
			p {margin:5px}
			ul {margin:1px}			
			h4 {margin:1px}	
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}
			table{
				width:1200px; 
				border-collapse:collapse; 
				text-align:center;
			}
			td,th{border:1px solid #696969}					
		</style>
	</head>
	<body>
		<div id="towrite" class="fixedBox"></div>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
			var bkcolor = $("body").css("backgroundColor");
			var tt = "";			
			window.onload = function() {
				var day = new Date();
				gt = day.getTime();			
				mymonth = day.getMonth()+1;
				myday = day.getDate();
				if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
				if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
				tt = day.getFullYear() + "-" + mymonth + "-" + myday;	
				tt = tt.replace(/-/g,""); 
				getfx();			
				start();
				changeStyle();
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					//getSource();
					//$("#ds").text('缓存首日开盘价……');
					setTimeout(function(){getSource()}, 1);					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				20000);
			})
						
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				obj1.style.left= "0px"; 				
				obj1.style.width= "100%";	
				//obj1.style.height= "620px";		
				obj1.style.fontSize="14px";						
			}	
						
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}						
										
			var trid = "";
			function changeCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid){  //过滤选中行
								this.style.background=bkcolor;
							}else{
								this.style.background="#483D8B";
							}
						}						
					}					
				}
			}			
			
			function NumberTransform(num) { 
				var result = num;
				if(Math.abs(num) > 100000000){
					result = num / 100000000;
					result = result.toFixed(2) + "亿";
				}else if(Math.abs(num) > 10000){
					result = num/10000;
					result = result.toFixed(2) + "万";
				}				   
				return result;  
			};	
			
			
			function getLastYearYestdy(){
				var strYear = new Date().getFullYear() - 1;  
				var strDay = new Date().getDate() + 1;  
				var strMonth = new Date().getMonth() + 1;
				if(strMonth<10){  
					strMonth="0"+strMonth;  
				}
				if(strDay<10){  
					strDay="0"+strDay;  
				}
				datastr = strYear+"-"+strMonth+"-"+strDay;
				return datastr;
			}


			function opzf(num1,num2) {			
				var a = parseFloat(num1); 
				var b = parseFloat(num2);				
				if (isNaN(a) || isNaN(b)){  				    
				   return "";  
				}
				if (a == 0 || b == 0){  				    
				   return "";  
				}					
				var result = ((a/b - 1) * 100).toFixed(2)						
				return result;  				
			}
			
			var result = [];
			function getfx() {  //新股数据
				//var url = "https://datacenter-web.eastmoney.com/api/data/v1/get?callback=jQuery112307036253828830779_1691482801666&sortColumns=LISTING_DATE,SECURITY_CODE&sortTypes=-1,-1&pageSize=5000&pageNumber=1&reportName=RPTA_APP_IPOAPPLY&columns=SECURITY_CODE,SECURITY_NAME,ISSUE_NUM,ISSUE_PRICE,CLOSE_PRICE,OPEN_PRICE,LISTING_DATE&quoteColumns=f2~01~SECURITY_CODE~NEWEST_PRICE&quoteType=0&filter=(APPLY_DATE>'2010-01-01')";
				var url = "https://datacenter-web.eastmoney.com/api/data/v1/get?callback=jQuery112307036253828830779_1691482801666&sortColumns=LISTING_DATE,SECURITY_CODE&sortTypes=-1,-1&pageSize=5000&pageNumber=1&reportName=RPTA_APP_IPOAPPLY&columns=SECURITY_CODE,SECURITY_NAME,ISSUE_NUM,ISSUE_PRICE,CLOSE_PRICE,OPEN_PRICE,LISTING_DATE&quoteColumns=f2~01~SECURITY_CODE~NEWEST_PRICE&quoteType=0&filter=(LISTING_DATE>='" + getLastYearYestdy() + "')";				
				$.ajax({
					type: "get",
					url: url,
					dataType: "text",
					async : false,
					cache:false,
					timeout:3000,						
					success: function(data) {							
						//document.write(data);						
						var ss = data.replace(/ /g,"")
						ss = ss.match(/,"data":(\S*),"count"/)[1];
						result =  JSON.parse(ss);
						//document.write(JSON.stringify(result));
					}
				});
			}
			
			var opens = [];
			var f = 0;
			function getopen(code){	
				var aa = null;				
				var arr = [];
				var url = 'https://datacenter-web.eastmoney.com/api/data/v1/get?callback=jQuery112302183295400694123_1691541296419&columns=ALL&source=NEEQSELECT&reportName=RPT_NEEQ_LDPERFORMANCE&filter=(SECURITY_CODE="' + code + '")';
				$.ajax({
					type: "get",
					url: url,
					dataType: "text",
					async : false,
					cache:false,
					timeout:3000,						
					success: function(data) {							
						//document.write(data);							
						if(data.indexOf('"result":null') == -1){
							var ss = data.replace(/ /g,"")
							ss = ss.match(/,"data":(\S*),"count"/)[1];
							arr =  JSON.parse(ss);
							//document.write(JSON.stringify(arr));							
						}					
					}
				});	
				
				if(arr.length != 0){
					aa = arr[0].OPEN_PRICE;										
				}
				
				if(localStorage.getItem('sropen') != null && f == 0){  
					var cc = localStorage.getItem('sropen');
					opens = JSON.parse(cc);	
					f++;
					//alert(JSON.stringify(opens))
				}	
								
				if(opens.indexOf(code) == -1 && aa != null){
					opens.push({"code":code,"open":aa});
				}
				return aa;
			}
			
			function start(){
				div = document.getElementById('towrite');
				var qh = "<a style='position:absolute; right:120px;font-size:14px;' href='javascript:void(0)' onclick='clearstorage()'>" + "清除缓存" + "</a>";							
				var ds = "<span id='ds' style='position:absolute; right:260px;font-size:14px;'><span>";
				div.innerHTML = "<font size='3'>东财新股" + qh + ds + "</font>";
				$("#ds").text('缓存首日开盘价……');
				setTimeout(function(){getSource()}, 1);
			}
			
			var rs = 4;  //默认主力净额高亮
			var fx = 1;				
			function getSource() {			    				
				div = document.getElementById('towrite');
				
				//var url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112404015733675234925_1691459750399&pn=1&pz=500&po=1&np=1&fltt=2&fid=f26&fs=m:0+f:8,m:1+f:8&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f11,f62,f128,f136,f115,f152"
				//var url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112404015733675234925_1691459750399&pn=1&pz=500&po=" + fx + "&np=1&fltt=2&fid=" + fid + "&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f11,f62,f128,f136,f115,f152"
				//var url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112404015733675234925_1691459750399&pn=1&pz=500&po=" + fx + "&np=1&fltt=2&fid=" + fid + "&fs=m:0+f:8,m:1+f:8,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f11,f62,f128,f136,f115,f152"
				var url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112404015733675234925_1691459750399&pn=1&pz=500&po=1&np=1&fltt=2&fid=f26&fs=m:0+f:8,m:1+f:8,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f11,f62,f128,f136,f115,f152"
				
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "text",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						var ss = data.replace(/ /g,"")
						ss = ss.match(/,"diff":(\S*)\}\}\);/)[1];
						//document.write(ss);
						
						var temp =  JSON.parse(ss);
						var arr = [];
						for (var i = 0; i < temp.length; i++){  //1、过滤日期，滤除一年前股票
							var srq = temp[i]["f26"];
							if(srq > getLastYearYestdy().replace(/-/g,"")){
								arr.push(temp[i]);
							}
						}
						
						//document.write(JSON.stringify(arr))
						var hh = 0;
						var temp2 = [];
						for (var i = 0; i < arr.length; i++){  //2、获取全部数据、计算涨跌幅
							var code = arr[i]["f12"];
							var name = arr[i]["f14"];
							var xj = arr[i]["f2"];	
							var zsp = arr[i]["f18"];  //昨收盘
							var srq = arr[i]["f26"];
							if(srq <= tt){
								var ISSUE_PRICE = 0;
								var ISSUE_NUM = 0;
								var OPEN_PRICE = 0;
								var CLOSE_PRICE = 0;
								var a = result.findIndex((v) => {  //(findIndex)判断数组有无指定对象   
									return v.SECURITY_CODE ===  code;
								});
								if(a > -1){
									
									var arrfind = result.find(function (item) {
										return item.SECURITY_CODE == code
									});
									ISSUE_PRICE = arrfind.ISSUE_PRICE; 
									ISSUE_NUM = arrfind.ISSUE_NUM;
									OPEN_PRICE = arrfind.OPEN_PRICE;									
									CLOSE_PRICE = arrfind.CLOSE_PRICE;
									if(tt == srq){  //当日取现价
										CLOSE_PRICE = xj;
									}
									//alert(JSON.stringify(arrfind))	
									//alert(OPEN_PRICE)
									if(OPEN_PRICE == null){
										if(tt == srq && code.substr(0,1) != "8" && code.substr(0,1) != "4"){  //当日新股无开盘价时刷新
											getfx();
										}
										if(localStorage.getItem('sropen') != null){											
											var aa = localStorage.getItem('sropen');
											//alert(aa);
											var bb = JSON.parse(aa);
											
											var a = bb.findIndex((v) => {  
												return v.code ===  code;
											});
											if(a > -1){
												var arrfind = bb.find(function (item) {
													return item.code == code
												});
												OPEN_PRICE = arrfind.open; 																
											}else{
												OPEN_PRICE = getopen(code);
												hh++;
											}											
										}else{																						
											OPEN_PRICE = getopen(code);
											hh++;
										}
									}
									
									if(xj == 0 && zsp != 0){  //盘前
										xj = zsp;
									}
									
									temp2.push({"代码":code,"名称":name,"最新价":arr[i]["f2"],"涨跌幅":arr[i]["f3"],"上市时间":srq,"首日涨幅":opzf(CLOSE_PRICE,ISSUE_PRICE),"首日实际涨幅":opzf(CLOSE_PRICE,OPEN_PRICE),"上市以来涨幅":opzf(xj,ISSUE_PRICE),"发行量":ISSUE_NUM.toFixed(0),"发行价":ISSUE_PRICE,
									"成交量":arr[i]["f5"],"成交额":arr[i]["f6"],"振幅":arr[i]["f7"],"换手率":arr[i]["f8"],"市盈率":arr[i]["f9"],"市净率":arr[i]["f23"]});
								
								}
							}	
						}
						//alert(JSON.stringify(temp2))
						//alert(hh)
						if(hh != 0){
							//localStorage.setItem('sropen', opens);  //写入缓存
							localStorage.setItem('sropen', JSON.stringify(opens));  //写入缓存
						}
						
						$("#ds").text("");
						
						function up(a,b){
							if(rs == 2){
								if(fx == 1){
									return b.最新价-a.最新价
								}else{
									return a.最新价-b.最新价
								}
							}else if(rs == 3){
								if(fx == 1){
									return b.涨跌幅-a.涨跌幅
								}else{
									return a.涨跌幅-b.涨跌幅
								}
							}else if(rs == 4){
								if(fx == 1){
									return b.上市时间-a.上市时间
								}else{
									return a.上市时间-b.上市时间
								}
							}else if(rs == 5){
								if(fx == 1){
									return b.首日涨幅-a.首日涨幅
								}else{
									return a.首日涨幅-b.首日涨幅
								}
							}else if(rs == 6){
								if(fx == 1){
									return b.首日实际涨幅-a.首日实际涨幅
								}else{
									return a.首日实际涨幅-b.首日实际涨幅
								}
							}else if(rs == 7){
								if(fx == 1){
									return b.上市以来涨幅-a.上市以来涨幅
								}else{
									return a.上市以来涨幅-b.上市以来涨幅
								}
							}else if(rs == 8){
								if(fx == 1){
									return b.发行量-a.发行量
								}else{
									return a.发行量-b.发行量
								}
							}else if(rs == 9){
								if(fx == 1){
									return b.发行价-a.发行价
								}else{
									return a.发行价-b.发行价
								}
							}else if(rs == 10){
								if(fx == 1){
									return b.成交量-a.成交量
								}else{
									return a.成交量-b.成交量
								}
							}else if(rs == 11){
								if(fx == 1){
									return b.成交额-a.成交额
								}else{
									return a.成交额-b.成交额
								}
							}else if(rs == 12){
								if(fx == 1){
									return b.振幅-a.振幅
								}else{
									return a.振幅-b.振幅
								}
							}else if(rs == 13){
								if(fx == 1){
									return b.换手率-a.换手率
								}else{
									return a.换手率-b.换手率
								}
							}else if(rs == 14){
								if(fx == 1){
									return b.市盈率-a.市盈率
								}else{
									return a.市盈率-b.市盈率
								}
							}else if(rs == 15){
								if(fx == 1){
									return b.市净率-a.市净率
								}else{
									return a.市净率-b.市净率
								}
							}							
						}
						
						temp2.sort(up);  //3、排序输出
						for (var i = 0; i < 50; i++){
							res.push(temp2[i]);
						}
					}
				});
				
				
				//document.write(JSON.stringify(res));
				
				var oTable = document.getElementById('gg');
				if(oTable){
					div.removeChild(oTable);  //清除table
				}
				var json = res;
				
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var n = 0;
				var b = 0;
				for(var key in json[0]){  //表头
					key = key.replace('市盈率','市盈率(动态)').replace('成交量','成交量(手)')					
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);
					if(m == rs){  //高亮
						n = m;
						th.style.color = "#FFFF00";							
					}					
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;
					var dm = "";
					var mc = "";
					for(var key in json[i]){ //行元素遍历						
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm;						
						}else if(p == 11 || p == 12){
							rc = NumberTransform(rc);
						}						
						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + rc + "</a>";
						
						if(p == 10 || p == 11){

						}						
						if(p == n + 1){														
							td.getElementsByTagName("a")[0].style.color = "#FFA500";
							if(fx == 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}
						
						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}					
				//var div = document.getElementById("towrite");									
				div.appendChild(table);
				table.id = "gg";
				makeSortable(table);
				hover();

				<!-- var div1 = document.getElementById('sropen'); -->
				<!-- if(div1){ -->
					<!-- div.removeChild(div1); 					 -->
				<!-- } -->
				<!-- var newDiv = document.createElement("div"); -->
				<!-- newDiv.id = "sropen";							 -->
				<!-- div.appendChild(newDiv);					 -->
				<!-- newDiv.innerHTML = "<p style='white-space:normal;'>" + localStorage.getItem('sropen') + "</p>"; -->
			}
			
			var pt = 1;
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						headers[n].onclick=function(){
							if(n >= 2){
								if(rs != n){  //切换列 清零
									rs = n;
									fx = 1;
									pt = 1;
								}else{
									fx = (pt%2 == 0) ? 1 : 0;
									pt++;
								}														
								getSource();								
							}							
						}
					}(i));
				}
			}
			
			function clearstorage(){
				if(localStorage.getItem('sropen') != null){						
					localStorage.removeItem('sropen'); //清除缓存localStorage
					opens = [];//初始化
				}
				
				alert('清除完成');
			}
			
		</script>	
	</body>
</html>